home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_d / tpop3.zip / POP3MAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1996-04-11  |  6KB  |  230 lines

  1. unit Pop3main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, POP3, Buttons, Grids, ExtCtrls,
  8.   Pop3Su, IniFiles, MsgDcd, mailbase;
  9.  
  10. type
  11.   TPOP3Form = class(TForm)
  12.     ToolBar: TPanel;
  13.     StatusBar: TPanel;
  14.     GetButton: TSpeedButton;
  15.     CancelButton: TSpeedButton;
  16.     SetupButton: TSpeedButton;
  17.     ExitButton: TSpeedButton;
  18.     InBox: TStringGrid;
  19.     POP3: TPOP3;
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  22.     procedure GetButtonClick(Sender: TObject);
  23.     procedure CancelButtonClick(Sender: TObject);
  24.     procedure ExitButtonClick(Sender: TObject);
  25.     procedure SetupButtonClick(Sender: TObject);
  26.     procedure FormResize(Sender: TObject);
  27.     procedure InBoxClick(Sender: TObject);
  28.     procedure POP3StatusChange(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.     IniName : string;
  32.     AttDir : string;
  33.   public
  34.     { Public declarations }
  35.     procedure ProcessInBox;
  36.     procedure EnableControls;
  37.     procedure DisableControls;
  38.   end;
  39.  
  40. var
  41.   POP3Form: TPOP3Form;
  42.  
  43. implementation
  44.  
  45. {$R *.DFM}
  46.  
  47. procedure TPOP3Form.FormCreate(Sender: TObject);
  48. begin
  49.   IniName:=ChangeFileExt(Application.ExeName,'.ini');
  50.   with TIniFile.Create(IniName) do
  51.   try
  52.     POP3.Server:=ReadString('Setup','Server','');
  53.     POP3.UserName:=ReadString('Setup','User Name','');
  54. {****** Warning!!! No Encription for Password!!! *****}
  55.     POP3.Password:=ReadString('Setup','Password','');
  56.     POP3.LogFileName:=ReadString('Setup','Log File','');
  57.     AttDir:=ReadString('Setup','Attachments','');
  58.   finally
  59.     free;
  60.   end;
  61.   InBox.Cells[0,0]:='From';
  62.   InBox.Cells[1,0]:='Subject';
  63.   InBox.Cells[2,0]:='Size';
  64. end;
  65.  
  66. procedure TPOP3Form.FormClose(Sender: TObject; var Action: TCloseAction);
  67. begin
  68.   with TIniFile.Create(IniName) do
  69.   try
  70.     WriteString('Setup','Server',POP3.Server);
  71.     WriteString('Setup','User Name',POP3.UserName);
  72. {****** Warning!!! No Encription for Password!!! *****}
  73.     WriteString('Setup','Password',POP3.Password);
  74.     WriteString('Setup','Log File',POP3.LogFileName);
  75.     WriteString('Setup','Attachments',AttDir);
  76.   finally
  77.     free;
  78.   end;
  79. end;
  80.  
  81. procedure TPOP3Form.DisableControls;
  82. var
  83.   i : Integer;
  84.   SB : TSpeedButton;
  85. begin
  86.   for i:=0 to ToolBar.ControlCount-1 do
  87.   begin
  88.     SB:=ToolBar.Controls[i] as TSpeedButton;
  89.     SB.Enabled:=SB.Tag=1;
  90.   end;
  91.   Cursor:=crHourGlass;
  92. end;
  93.  
  94. procedure TPOP3Form.EnableControls;
  95. var
  96.   i : Integer;
  97.   SB : TSpeedButton;
  98. begin
  99.   for i:=0 to ToolBar.ControlCount-1 do
  100.   begin
  101.     SB:=ToolBar.Controls[i] as TSpeedButton;
  102.     SB.Enabled:=SB.Tag<>1;
  103.   end;
  104.   Cursor:=crDefault;
  105. end;
  106.  
  107. procedure TPOP3Form.GetButtonClick(Sender: TObject);
  108. begin
  109.   if (POP3.Server='') or (POP3.UserName='') or
  110.      (POP3.Password='') then
  111.    MessageDlg('You might want to enter the information'^M^J+
  112.               'in the Setup dialog box...',mtError,[mbOk],0)
  113.   else
  114.   with POP3 do
  115.   begin
  116.     try
  117.       DisableControls;
  118.       Open;
  119.       LogIn;
  120.       GetStatistics;
  121.       if TotalMessages>0 then
  122.         GetMessages;
  123.       LogOut;
  124.     finally
  125.       Close;
  126.       EnableControls;
  127.     end;
  128.   end;
  129.   ProcessInBox;
  130. end;
  131.  
  132. procedure TPOP3Form.ProcessInBox;
  133. var
  134.   i : Integer;
  135. begin
  136.   if POP3.MailMessages.Count>0 then
  137.   begin
  138.     InBox.Enabled:=true;
  139.     InBox.RowCount:=POP3.MailMessages.Count+1;
  140.     for i:=1 to Pop3.MailMessages.Count do
  141.     with TMailMessage(POP3.MailMessages.Objects[i-1]) do
  142.     begin
  143.       InBox.Cells[0,i]:=From;
  144.       InBox.Cells[1,i]:=Subject;
  145.       InBox.Cells[2,i]:=IntToStr(Size);
  146.     end;
  147.     InBox.Repaint;
  148.     StatusBar.Caption:='Highlight a message you wish to process and press Enter';
  149.   end
  150.   else
  151.     StatusBar.Caption:='No New Messages';
  152. end;
  153.  
  154. procedure TPOP3Form.CancelButtonClick(Sender: TObject);
  155. begin
  156.   Pop3.Cancel;
  157. end;
  158.  
  159. procedure TPOP3Form.ExitButtonClick(Sender: TObject);
  160. begin
  161.   Close;
  162. end;
  163.  
  164. procedure TPOP3Form.SetupButtonClick(Sender: TObject);
  165. begin
  166.   with TSetupDlg.Create(Self) do
  167.   try
  168.     ServerEdit.Text:=POP3.Server;
  169.     UserNameEdit.Text:=POP3.UserName;
  170.     PasswordEdit.Text:=POP3.Password;
  171.     LogFileNameEdit.Text:=POP3.LogFileName;
  172.     AttDirEdit.Text:=AttDir;
  173.     if ShowModal=mrOk then
  174.     begin
  175.       POP3.Server:=ServerEdit.Text;
  176.       POP3.UserName:=UserNameEdit.Text;
  177.       POP3.Password:=PasswordEdit.Text;
  178.       POP3.LogFileName:=LogFileNameEdit.Text;
  179.       AttDir:=AttDirEdit.Text;
  180.     end;
  181.   finally
  182.     free;
  183.   end;
  184. end;
  185.  
  186. procedure TPOP3Form.FormResize(Sender: TObject);
  187. begin
  188.   with InBox do
  189.   begin
  190.     ColWidths[0]:=Trunc(0.25*Width);
  191.     ColWidths[1]:=Trunc(0.5*Width);
  192.     ColWidths[2]:=Trunc(0.25*Width);
  193.   end;
  194. end;
  195.  
  196. procedure TPOP3Form.InBoxClick(Sender: TObject);
  197. var
  198.   MailMessage : TMailMessage;
  199. begin
  200.   MsgDcd.AttachmentsDir:=AttDir;
  201.   MailMessage:=TMailMessage(POP3.MailMessages.Objects[InBox.Row-1]);
  202.   MailMessage.Body.Position:=0;
  203.   with TMsgProcessor.Create(Self,MailMessage.Body) do
  204.   try
  205.     ShowModal;
  206.   finally
  207.     free;
  208.   end;
  209. end;
  210.  
  211. procedure TPOP3Form.POP3StatusChange(Sender: TObject);
  212. var
  213.   s : string;
  214. begin
  215.   case POP3.Status of
  216.    psIdle : s:='';
  217.    psResolving : s:='Resolving remote host';
  218.    psConnecting : s:='Connecting to server';
  219.    psLogIn : s:='Logging In';
  220.    psLogOut : s:='Logging Out';
  221.    psRetrieving : s:='Retrieving Message(s)';
  222.    psDeleting : s:='Deleting Message(s)';
  223.    psCancel : s:='Canceled';
  224.    psTimeOut : s:='Timed Out';
  225.   end;
  226.   StatusBar.Caption:=s;
  227. end;
  228.  
  229. end.
  230.